// void, Obj me, Item item, Obj h

Hero  this;
Unit  unit;
point pt;
bool  bRunAway;
int   nDist;

this = me.AsHero;
Sleep(10);
if(!.IsValid) return;

if(.HasItem("irage_battle")) return;
if(.HasItem("irage_battle_stand")) return;
if(.HasItem("igreat_charge")) return;
if(.HasItem("iretreat_notai")) return;

unit = h.AsUnit;

nDist = .PathTo(unit, .FormRadius, 0);
if (nDist == -1)
	return;

if (nDist > .sight)
{
	.FormSetupAndMoveTo(unit, 0, 0,true);
	while (.HasPath){
		.FormKeepMoving(1500);
	}
}
else
	.army.SetCommand("stand_position");

pt = .posRH;
while (!.Goto(unit, GetConst("GiveDistance"), 1500, false, 5000))
{
	if (.PathTo(pt, 0, 0) > .FormRadius + 50)
	{
		pt.Set(.posRH.x + 1, .posRH.y + 1);
		.FormSetupAndMoveTo(pt, 0, 0, true);
		while (.HasPath)
			.FormKeepMoving(1500);
		if (.PathTo(unit, .FormRadius, 0) > 50)
		{
			.FormSetupAndMoveTo(unit, 0, 0, true);
			while (.HasPath)
				.FormKeepMoving(1000);
			pt = .posRH;
		}
	}
	if (!unit.IsAlive) {
		Sleep(10+rand(100));
		return;
	}
	if (unit.InHolder) {
		Sleep(10+rand(100));
		return;
	}
}
.GiveItem(item, unit);

if (.HasArmy) 
	while (!.Goto(pt, 0, 1500, false, 5000));
